﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UniversityStudentManagemnetSystem.BLL;
using UniversityStudentManagemnetSystem.DAO.DAL;

namespace UniversityStudentManagemnetSystem.UI
{
    public partial class DesignationPage : System.Web.UI.Page
    {
        DesignationManager designationManager = new DesignationManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Account/Login.aspx", false);
            }

        }

        protected void designationSaveButton_Click(object sender, EventArgs e)
        {
            if (designationNameTextBox.Text!="")
            {
                try
                {
                    Designation designation = new Designation();
                    designation.DesignationName = designationNameTextBox.Text;
                    if (designationManager.SaveDesignation(designation))
                    {
                        designationSaveMessageLabel.ForeColor = Color.Green;
                        designationSaveMessageLabel.Text = "Saved Succesfully";
                    }
                }
                    catch(FormatException exception)
                    {

                        designationSaveMessageLabel.ForeColor = Color.Red;
                        designationSaveMessageLabel.Text = exception.Message;
                    }
                catch (Exception exception)
                {
                    designationSaveMessageLabel.ForeColor = Color.Red;
                    designationSaveMessageLabel.Text = exception.Message;
                } 
            }
            else
            {
                designationSaveMessageLabel.ForeColor = Color.Red;
                designationSaveMessageLabel.Text = "Please fill up the all fields.";
            }
        }
    }
}